package kr.ac.kaist.vrowser.tts;

import java.util.Locale;

import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;

public class VrowserTextToSpeech implements TextToSpeech.OnInitListener {
	
	private boolean initialized = false;
	private TextToSpeech tts;
	private Locale locale = null;
	
	public VrowserTextToSpeech(Context context) {
		tts = new TextToSpeech(context, this);
	}

	public void onInit(int status) {
		 if (status == TextToSpeech.SUCCESS) {
			int result = tts.setLanguage(Locale.KOREA);
	        if (result == TextToSpeech.LANG_MISSING_DATA
	         || result == TextToSpeech.LANG_NOT_SUPPORTED) {
	        	Log.e("TTS", "This Korean Language is not supported");
	        	result = tts.setLanguage(Locale.US);
		        if (result == TextToSpeech.LANG_MISSING_DATA
		         || result == TextToSpeech.LANG_NOT_SUPPORTED) {        	
		        	Log.e("TTS", "This English Language is not supported");
		        } else {
		        	initialized = true;
		        	locale = Locale.US;
		        }
	        } else {
	        	initialized = true;
	        	locale = Locale.KOREA;
	        }
	     } else {
	    	Log.e("TTS", "Initilization Failed!");
	     }
	}

	public TextToSpeech getTextToSpeech() {
		if (initialized)
			return tts;
		else 
			return null;
	}
	
	public Locale getLocale() {
		return locale;
	}
}
